<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>类中的方法this指向</title>
</head>

<body>
  <script type="text/javascript">
    class Boy {
      constructor(name, age) {
        this.name = name
        this.age = age
      }
      speak() {
        // 类中所有定义的方法，已经默认全部开启了严格模式，所以不会指向window
        console.log(this)
      }
    }

    const b1 = new Boy('我是ed.', 10)
    b1.speak()  //  通过实例调用

    const x  = b1.speak
    x()

    function demo() {
      'use strict'
      console.log(this)
    }
    demo()

  </script>
</body>

</html>